package com.example.samplemanagement.model;

import com.fasterxml.jackson.annotation.JsonIgnore; // Import this annotation
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List; // Import List
// import com.example.samplemanagement.model.Feedback; // Removed Feedback import as per user request
// import com.example.samplemanagement.model.Delivery; // Removed Delivery import as it's no longer used

// Customer.java
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "customer")
public class Customer {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(unique = true, nullable = false)
    private String companyName; // Company Name
    @Column(nullable = false)
    private String contactPerson; // Primary Contact
    private String contactPhone; // Contact Phone
    private String customerLevel; // Customer Level (e.g., VIP, Normal, Potential)
    private String responsibleSales; // Responsible Sales

    @Column(updatable = false)
    private LocalDateTime creationDate;
    private LocalDateTime lastUpdated;

    // IMPORTANT: Keep this SampleTracking-related List and annotate with @JsonIgnore
    // Assuming a OneToMany relationship between Customer and SampleTracking
    @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
    @JsonIgnore // <--- Add this annotation
    private List<SampleTracking> sampleTrackings;

    // Removed Delivery related OneToMany relationship as per user request
    // @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
    // @JsonIgnore
    // private List<Delivery> deliveries;

    // Removed Feedback related OneToMany relationship as per user request
    // @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL, orphanRemoval = true)
    // @JsonIgnore
    // private List<Feedback> feedbacks;


    @PrePersist
    protected void onCreate() {
        this.creationDate = LocalDateTime.now();
        this.lastUpdated = LocalDateTime.now();
    }

    @PreUpdate
    protected void onUpdate() {
        this.lastUpdated = LocalDateTime.now();
    }
}
